SpaceToDepth
将输入张量的空间维按块(block)重组到深度通道(channel)中。
假设输入形状为: [N, H, W, C],块大小为 B,则输出形状为:
\[\text{out\_shape} = [N, H/ B, W / B, C * B * B]\]对应元素映射为:
\[output[n, h_{out}, w_{out}, c * B * B + (l * B + m)] = input[n, h_{out} * B + l, w_{out} * B + m, c]\]
- 输入:
input - 输入数据地址,按 NHWC 存储。
in_shape - 指向长度为4的数组,表示输入维度 [N, H, W, C]。
block - block 大小。
data_size - 每个元素的字节大小。
core_mask(int, 可选) - 核掩码(仅适用于共享存储版本)。
- 输出:
output - 输出数据地址。
- 支持平台:
FT78NEMT7004备注
FT78NE 支持 fp32, fp64, cplx64, cplx128, int16, int8, int32
MT7004 支持 fp32, fp16, cplx64, int16, int32
共享存储版本:
-
void i8_spacetodepth_s(int8_t *input, int8_t *output, const int *in_shape, int block, int data_size, int core_mask)
-
void i16_spacetodepth_s(int16_t *input, int16_t *output, const int *in_shape, int block, int data_size, int core_mask)
-
void i32_spacetodepth_s(int32_t *input, int32_t *output, const int *in_shape, int block, int data_size, int core_mask)
-
void hp_spacetodepth_s(half *input, half *output, const int *in_shape, int block, int data_size, int core_mask)
-
void fp_spacetodepth_s(float *input, float *output, const int *in_shape, int block, int data_size, int core_mask)
-
void dp_spacetodepth_s(double *input, double *output, const int *in_shape, int block, int data_size, int core_mask)
-
void c64_spacetodepth_s(float *input, float *output, const int *in_shape, int block, int data_size, int core_mask)
-
void c128_spacetodepth_s(double *input, double *output, const int *in_shape, int block, int data_size, int core_mask)
C调用示例:
1#include <stdio.h> 2 3int main(int argc, char* argv[]) { 4 float *input = (float *)0xA0000000; // 多核版:输入在 DDR 区域 5 float *output = (float *)0xB0000000; // 多核版:输出在 DDR 区域 6 int in_shape[4] = {1, 8, 8, 1}; // N,H,W,C 7 int block = 2; 8 int core_mask = 0xff; 9 fp_spacetodepth_s(input, output, in_shape, block, sizeof(float), core_mask); 10 return 0; 11}
私有存储版本:
-
void i8_spacetodepth_p(int8_t *input, int8_t *output, const int *in_shape, int block, int data_size)
-
void i16_spacetodepth_p(int16_t *input, int16_t *output, const int *in_shape, int block, int data_size)
-
void i32_spacetodepth_p(int32_t *input, int32_t *output, const int *in_shape, int block, int data_size)
-
void hp_spacetodepth_p(half *input, half *output, const int *in_shape, int block, int data_size)
-
void fp_spacetodepth_p(float *input, float *output, const int *in_shape, int block, int data_size)
-
void dp_spacetodepth_p(double *input, double *output, const int *in_shape, int block, int data_size)
-
void c64_spacetodepth_p(float *input, float *output, const int *in_shape, int block, int data_size)
-
void c128_spacetodepth_p(double *input, double *output, const int *in_shape, int block, int data_size)
C调用示例:
1#include <stdio.h> 2 3int main(int argc, char* argv[]) { 4 float *input = (float *)0x10000000; // 单核版:输入在 L2 5 float *output = (float *)0x10010000; // 单核版:输出在 L2 6 int in_shape[4] = {1, 8, 8, 1}; 7 int block = 2; 8 fp_spacetodepth_p(input, output, in_shape, block, sizeof(float)); 9 return 0; 10}